<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>JSONP跨域实例-百度搜索</title>
		<style type="text/css"></style>
		<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
	</head>
	<body>
		<input type="text">
		<ul></ul>
		
		<script>
			function getData(data){//接受数据
				var script = document.getElementById("jsonp");
				script.parentNode.removeChild(script);
				
				$("ul").html("");
				for(var i = 0; i < data.s.length; i++){
					$("<li>" + data.s[i] + "</li>").appendTo("ul");
				}
			}
			
			function getList(wd){
				var script = document.createElement("script");
				script.id = "jsonp";
				script.src = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?cb=getData&wd=" + wd;
				document.body.appendChild(script);
			}
			
			$("input").keyup(function(){
				var wd = $(this).val();
				getList(wd);
			})
			
		</script>
	</body>
</html>
